<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Order;
use backend\assets\AppAsset;
/* @var $this yii\web\Viedw */
/* @var $model common\models\Order */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="order-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'id')->textInput(['maxlength' => true,'readonly'=>'readonly']) ?>

    <?= $form->field($model, 'user_id')->textInput(['readonly'=>'readonly']) ?>

    <?= $form->field($model, 'order_status')->dropDownList(Order::itemAlias('order_status'),array('disabled'=>"disabled")) ?>
        
    <?= $form->field($model, 'shipping_status')->dropDownList(Order::itemAlias('shipping_status')) ?>

    <?= $form->field($model, 'pay_status')->dropDownList(Order::itemAlias('pay_status'),array('disabled'=>"disabled")) ?>

    <?= $form->field($model, 'product_num')->textInput(['readonly'=>'readonly']) ?>

    <?= $form->field($model, 'product_fee')->textInput(['maxlength' => true,'readonly'=>'readonly']) ?>

   <!--  <?= $form->field($model, 'shipping_id')->dropDownList(Order::ship_list()) ?>  -->

    <?php  $form->field($model, 'address_id')->textInput(['readonly'=>'readonly']) ?>
    <?php 
        if(Yii::$app->request->get('id')){
            $id = Yii::$app->request->get('id');
            $add_id = Order::findOne($id)->user_id;
            $query = Order::address_list($add_id);
        }else{
            $query = Order::address_list(0);
        }
        echo $form->field($model, 'address_id')->dropDownList($query,array('disabled'=>'disabled'));
    ?>

    <?= $form->field($model, 'shipping_fee')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'order_fee')->textInput(['maxlength' => true,'readonly'=>'readonly']) ?>

    <?= $form->field($model, 'pay_fee')->textInput(['maxlength' => true,'readonly'=>'readonly']) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<?php $this->beginBlock('footer_js') ?>
    $(function(){
        $('#order-user_id').blur(function(){
            var id = $(this).val();
            if(id){
                var address = '';
                $.ajax({
                    type: "POST",
                    url: "/order/getlist" ,
                    data: { uid:id },
                    success: function (data) {
                        var data = eval('('+data+')');
                        for(var k in data){
                            address += '<option value="'+k+'">'+data[k]+'</option>';
                        }
                        $('#order-address_id').html(address);
                    }
                });
            }
        });
    })
<?php $this->endBlock() ?>  
<?php $this->registerJs($this->blocks['footer_js'], \yii\web\View::POS_END); ?>
